import Cookies from 'js-cookie';
import {logout} from "@/api/index";

const user = {
    state: {},
    mutations: {
        logout(state, vm) {
            Cookies.remove('userInfo');
            Cookies.remove('access');
            // 清空打开的页面等数据
            localStorage.clear();
        }
    },
    actions: {
        // 退出登录
        handleLogout({state, commit}) {
            return new Promise((resolve, reject) => {
                logout().then(res => {
                    commit('logout')
                    resolve(res)
                }).catch(err => {
                    reject(err)
                })

            })
        }
    }
};

export default user;
